Translating Double Dispatch into Single Dispatch
نویسندگان
چکیده
Goals of flexibility and re-usability in typed object-oriented languages suggest the requirement of double dispatch, i.e., the mechanism of dynamically selecting a method not only according to the run-time type of the receiver (single dispatch), but also to the run-time type of the argument. However, many mainstream languages, such as, e.g., C++ and Java, do not provide it, resorting to only single dispatch. In this paper we present a general technique for adding double dispatch as a type-safe language feature, so yielding dynamic overloading and covariant specialization of methods, without extending basic semantics. To this aim we introduce a toy core language, extended to a full form of (non encapsulated) multi methods. Then we define a translation algorithm from multi methods to the core language, that implements double dispatch by using only standard mechanisms of static overloading and single dispatch. As a main feature, our translation preserves type safety, it uses neither RTTI nor type downcasts and does not introduce crucial overhead during method selection.
منابع مشابه
Double dispatch in C++
Double dispatch is the ability of selecting dynamically a method not only according to the run-time type of the receiver (single dispatch), but also to the run-time type of the argument. This mechanism unleashes the power of dynamic binding in object-oriented languages, so enhancing re-usability and separation of responsibilities. However, many mainstream languages, such as, e.g., C++ and Java,...
متن کاملMulti-Dispatch in the Java Virtual Machine: Design and Implementation
Mainstream object-oriented languages, such as C++ and Java1, provide only a restricted form of polymorphic methods, namely uni-receiver dispatch. In common programming situations, developers must work around this limitation. We describe how to extend the Java Virtual Machine to support multi-dispatch and examine the complications that Java imposes on multidispatch in practice. Our technique avo...
متن کاملMulti-Method Dispatch Using Single-Receiver Projections
A new technique for multi-method dispatch, called Single-Receiver Projections and abbreviated SRP, is presented. It operates by performing projections onto single-receiver dispatch tables, and thus benefits from existing research into single-receiver dispatch techniques. It provides method dispatch in O(k), where k is the arity of the method. Unlike existing multi-method dispatch techniques, it...
متن کاملIncremental Table-Based Method Dispatch for Reflective Object-Oriented Languages
A collection of algorithms and data structures are presented which provide incremental dispatch table modification. Incrementally modified dispatch tables allow table-based dispatch techniques to be used in reflective, dynamically typed, single-receiver languages with type/implementation-paired multiple inheritance. By storing a small amount of information, the algorithms can incrementally main...
متن کاملIncremental Table-based Method Dispatch for Reeexive Object-oriented Languages
A collection of algorithms and data structures are presented which provide incremental dispatch table modiication. Incrementally modiied dispatch tables allow table-based dispatch techniques to be used in reeexive, dynamically typed, single-receiver languages with type/implementation-paired multiple inheritance. By storing a small amount of information, the algorithms can incrementally maintain...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید
ثبت ناماگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید
ورودعنوان ژورنال:
- Electr. Notes Theor. Comput. Sci.
دوره 138 شماره
صفحات -
تاریخ انتشار 2005